package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallPointsProductStockRecordModel;
import com.mallcloud.mall.mall.api.entity.vo.PointProductStockRecordVO;
import com.mallcloud.mall.mall.service.MallPointsProductStockRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-积分商品-库存记录")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/pointsProductStockRecord")
public class MallPointsProductStockRecordController {
	private final MallPointsProductStockRecordService pointProductStockRecordService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductstockrecord_view')")
	public R<IPage<MallPointsProductStockRecordModel>> page(Page page, MallPointsProductStockRecordModel dto) {
		return R.ok(pointProductStockRecordService.page(page, Wrappers.query(dto)));
	}

	@ApiOperation("获取详情")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductstockrecord_view')")
	public R<PointProductStockRecordVO> getById(@PathVariable("id") Long id) {
		return R.ok(pointProductStockRecordService.getInfo(id));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductstockrecord_add')")
	public R save(@RequestBody MallPointsProductStockRecordModel dto) {
		return R.ok(pointProductStockRecordService.save(dto));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductstockrecord_edit')")
	public R updateById(@RequestBody MallPointsProductStockRecordModel dto) {
		return R.ok(pointProductStockRecordService.updateById(dto));
	}

	@ApiOperation("导出")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_pointsproductstockrecord_export')")
	public List<MallPointsProductStockRecordModel> export(MallPointsProductStockRecordModel dto) {
		return pointProductStockRecordService.list(Wrappers.query(dto));
	}
}
